﻿using System.Reflection;
using Autofac;
using Autofac.Integration.Mvc;
using Portal.Presentation;

namespace Portal.Logic.Bootstraper
{
	public class PresentationRegistrationModule : Autofac.Module
	{
		protected override void Load(ContainerBuilder builder)
		{
			builder.RegisterControllers(typeof(MvcApplication).Assembly);

			var assembly = Assembly.GetExecutingAssembly();

			builder.RegisterAssemblyTypes(assembly)
				.Where(t => t.Name.EndsWith("Provider"))
				.AsImplementedInterfaces();

			builder.RegisterAssemblyTypes(assembly)
				.Where(t => t.Name.EndsWith("Converter"))
				.AsImplementedInterfaces();

			builder.RegisterAssemblyTypes(assembly)
				.Where(t => t.Name.EndsWith("Service"))
				.AsImplementedInterfaces()
				.InstancePerHttpRequest();
		}
	}
}